package cn.itlaobing.dao;

import cn.itlaobing.model.ShoopingCarModel;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * Created by Administrator on 2017-11-20.
 */
public class ShoopingCarDao extends BaseDao{
    public List<ShoopingCarModel> findAll() throws SQLException {
        QueryRunner qr=new QueryRunner(getDataSource());
        String sql="SELECT shopid shopId ,userid userId,shopcount goodCount,goodid goodId,offlineid offlineId,picUrl goodImg ,goodname goodName,goodprice goodPrice FROM (" +
                " SELECT c.id shopid,c.member_id userid,c.count shopcount,c.good_id goodid,c.offline_shop_id offlineid ,good.good_name goodname,good.price goodprice FROM itlb_shop_cars c " +
                " LEFT JOIN itlb_goods good" +
                " ON c.good_id=good.id " +
                " WHERE c.member_id=6" +
                " )t" +
                " RIGHT JOIN itlb_goods_pic pic" +
                " ON t.goodId=pic.goodsId";
        BeanListHandler<ShoopingCarModel> beanListHandler=new BeanListHandler<ShoopingCarModel>(ShoopingCarModel.class);
        return qr.query(sql,beanListHandler);

    }
}